﻿using System;
using System.Collections.Generic;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PhoneMap.Common
{
    public class UserSetting
    {
        private static UserSetting instance;
        public static UserSetting Instance
        {
            get
            {
                if (instance == null)
                    instance = new UserSetting();
                return UserSetting.instance;
            }
        }
        public void SaveTokenFbData(string TokenFB)
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains("TokenFB"))
                IsolatedStorageSettings.ApplicationSettings.Remove("TokenFB");
            var settings = IsolatedStorageSettings.ApplicationSettings;
            settings.Add("TokenFB", TokenFB);
            settings.Save();
        }
        public string GetTokenFacebook()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;
            string token;
            settings.TryGetValue<string>("TokenFB", out token);
            if (token != string.Empty)
                return token;
            return string.Empty;
        }
        public void ClearnData()
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains("loginType"))
                IsolatedStorageSettings.ApplicationSettings.Remove("loginType");
        }
        public void ClearnFlagLogin()
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains("isLoginFacebook"))
                IsolatedStorageSettings.ApplicationSettings.Remove("isLoginFacebook");
        }
        public bool GetIsLoginFacebook()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;
            bool login;
            settings.TryGetValue<bool>("isLoginFacebook", out login);
            return login;
        }
        public void SaveIsLoginFacebook(bool isLogin)
        {
            ClearnFlagLogin();
            var settings = IsolatedStorageSettings.ApplicationSettings;
            settings.Add("isLoginFacebook", isLogin);
            settings.Save();
        }
       
        public void SaveLoginStatus(bool IsSave)
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;
            if (settings.Contains("IsSave"))
                settings.Remove("IsSave");
            settings.Add("IsSave", IsSave);
            settings.Save();
        }
        public bool GetLoginStatus()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;
            bool login;
            settings.TryGetValue<bool>("IsSave", out login);
            return login;
        }
        public void RemoveLoginStatus()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;
            if (settings.Contains("IsSave"))
                settings.Remove("IsSave");
        }
        public void SavePassword(string IsSave)
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;
            if (settings.Contains("SavePassword"))
                settings.Remove("SavePassword");
            settings.Add("SavePassword", IsSave);
            settings.Save();
        }
        public string GetPassword()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;
            string login;
            settings.TryGetValue<string>("SavePassword", out login);
            return login;
        }
        public void SaveFacebookId(string IsSave)
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;
            if (settings.Contains("SaveFacebookId"))
                settings.Remove("SaveFacebookId");
            settings.Add("SaveFacebookId", IsSave);
            settings.Save();
        }
        public string GetFacebookId()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;
            string login;
            settings.TryGetValue<string>("SaveFacebookId", out login);
            return login;
        }
    }
}
